use super::{
    err, err_value, json, ok, throw_err, Base, ECode, MapSv, Resp, SvCache, VBase, VMap, Value,
};

pub struct Real;

impl Base for Real {}

impl Real {
    pub async fn do_cmd(&self, para: &Value, cmd: &str, cache: SvCache) -> Resp {
        let data = para.ckobj()?;

        match cmd {
            "get" => self.do_get(data, cache).await,
            _ => throw_err!(ECode::NoServe, "no real serve"),
        }
    }

    async fn do_get(&self, data: &MapSv, cache: SvCache) -> Resp {
        let id = data.ck_str("uid")?;
        let ret = cache.get(id).ok_or(err_value(ECode::EmptyData, "empty"))?;

        ok!(ret)
    }
}
